#!/usr/bin/python
from Prototypes import *

class Form(Tag,Container,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		Container.__init__(self)
		FormField.__init__(self)
		self.tag = "form"

	def render(self, renderer):
		self.attributes['name']=self.id
		self.attributes['id']=self.id

		self.render_tag(renderer)
		self.render_contained(renderer)
		self.render_close(renderer)

class TextBox(Tag,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		FormField.__init__(self)
		self.text=""	
		self.tag="input"
		self.attributes['type'] = 'text'

	def render(self,renderer):
		self.attributes['name']=self.id
		self.attributes['id']=self.id

		self.render_tag(renderer)
		renderer.write(text)
		self.render_close(renderer)

class TextArea(Tag,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		FormField.__init__(self)
		self.text=""	
		self.tag="textarea"

	def render(self,renderer):
		self.attributes['name']=self.id
		self.attributes['id']=self.id
		self.render_tag(renderer)
		renderer.write(text)
		self.render_close(renderer)

class Label(Tag,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		FormField.__init__(self)
		self.text=""
		self.tag="label"

	def render(self,renderer):
		self.attributes['name']=self.id
		self.attributes['id']=self.id
		self.render_tag(renderer)
		renderer.write(text)
		self.render_close(renderer)
	
	def attach(control):
		self.attributes['for']=control.id

class Button(Tag,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		FormField.__init__(self)
		self.text=""
		self.tag='input'

	def render(self,renderer):
		self.attributes['name']=self.id
		self.attributes['id']=self.id
		self.attributes['type']='submit'
		self.attributes['value']=self.text		
		self.render_tag(renderer)
		self.render_close(renderer)

class Select(Tag,Container,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		Container.__init__(self)
		FormField.__init__(self)
		self.tag="select"

	def render(self,renderer):
		self.attributes['name']=self.id
		self.attributes['id']=self.id
		self.render_tag(renderer)
		self.render_contained(renderer)
		self.render_close(renderer)


class Option(Tag,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		FormField.__init__(self)
		self.value=""
		self.text=""
		self.tag="option"

	def render(self,renderer):
		self.attributes['value']=self.value
		self.render_tag(renderer)
		renderer.write(self.text)
		self.render_close(renderer)


class CheckBox(Tag,Renderable,FormField):
	def __init__(self):
		Tag.__init__(self)
		FormField.__init__(self)
		self.value=""
		self.tag="checkbox"
		self.checked=False

	def render(self,renderer):
		self.attributes['id']=self.id
		self.attributes['name']=self.id		
		self.attributes['value']=self.value	
		if(self.checked):
			self.attributes['checked']='checked'
		self.render_tag(renderer)
		self.render_close(renderer)

